//
//  AppDelegate.m
//  DLBaseProject
//
//  Created by 谢东来 on 2021/7/13.
//  Copyright © 2021 XDL. All rights reserved.
//

#import "AppDelegate.h"
#import "BaseTabBarController.h"
#import <AVFoundation/AVFoundation.h>

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    BaseTabBarController *tab = [[BaseTabBarController alloc] init];
    self.window.rootViewController = tab;
    [self.window makeKeyAndVisible];
    
    [[DataManager shareManager] readingData];
    if (![DataManager shareManager].dataModel) {
        [DataManager shareManager].dataModel = [[DataModel alloc] init];
    }
    
    [self showLoginPage];
    
    
    AVAudioSession *session = [AVAudioSession sharedInstance];
        [session setActive:YES error:nil];
        [session setCategory:AVAudioSessionCategoryPlayback error:nil];
    NSError *error;
        [[AVAudioSession sharedInstance] setActive:YES error:&error];
        //注，ios9上不加这一句会无效
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
   
    return YES;
}

- (void)showLoginPage {
    BaseTabBarController *tab = (BaseTabBarController*)self.window.rootViewController;
    RegisterViewController *v = [[RegisterViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:v];
    nav.modalPresentationStyle = UIModalPresentationFullScreen;
    [tab.selectedViewController presentViewController:nav animated:NO completion:^{
//        tab.selectedIndex = 0;
    }];
    
//    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
//        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
        // 这里判断是否第一次
//        hDisplayView *hvc = [[hDisplayView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
//        [v.view addSubview:hvc];
//    }
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"SHARENOTI" object:nil];
}


@end
